from sqlmodel import create_engine, Session, SQLModel



#数据库访问地址
DATABASE_URL = "mysql+pymysql://root:halo123456@172.18.0.3:3306/fastapi?charset=utf8mb4"
engine = create_engine(
    DATABASE_URL,
    echo=True,
    pool_size=10,
    max_overflow=20,
    pool_pre_ping=True  # 自动检测断开的连接
)

def init_db():
    SQLModel.metadata.create_all(engine)
    # 可选：创建初始数据

def get_session():
    with Session(engine) as session:
        yield session
